/**
 * 
 */
package com.dsteiner.gwt.cafeteriasophia.client.model;

import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.Map;

import com.dsteiner.widgets.client.PropertyChangeCollection;
import com.dsteiner.widgets.client.Widgets.IWidget;

public class NavModel {
	public static final int PAGE_ID_SHIFT_CHANGE = 1;
	public static final int PAGE_ID_NAV = 0;
	public static final int PAGE_ID_HISTORY = 2;
	public static final int PAGE_ID_STATISTIC = 3;
	
	private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
			this);

	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
		propertyChangeSupport.registerPropertyChangeListener(propertyName, listener);
	}

	private Map<Integer, IWidget> pageMap = new HashMap<Integer, IWidget>();

	private int selectedPage = PAGE_ID_NAV;

	public int getSelectedPage() {
		return selectedPage;
	}

	public void setSelectedPage(int selectedPage) {
		int oldSelectedPage = this.selectedPage;
		this.selectedPage = selectedPage;
		propertyChangeSupport.firePropertyChange("selectedPage", oldSelectedPage, selectedPage);
	}
	public Map<Integer, IWidget> getPageMap() {
		return pageMap;
	}

	public void setPageMap(Map<Integer, IWidget> pageMap) {
		Map<Integer, IWidget> oldPageMap = this.pageMap;
		this.pageMap = pageMap;
		propertyChangeSupport.firePropertyChange("pageMap", oldPageMap, pageMap);
	}
	public void addPage(int pageId, IWidget widget){
		Map<Integer, IWidget> newPageMap = new HashMap<Integer, IWidget>();
		newPageMap.put(pageId, widget);
		newPageMap.putAll(pageMap);
		setPageMap(newPageMap);
	}
}